// import axios from "axios"

// CDN引入
import nprogress from "nprogress"

import 'nprogress/nprogress.css'

//! 创建axios 实例
const instance = axios.create({
  baseURL: 'https://api-hmugo-web.itheima.net/api',
  timeout: 10000
});

// 拦截器，请求拦截
instance.interceptors.request.use(config=>{

    // 部分接口需要拿到token
    let token = ""
    if(token){
      config.headers = {
        "aaa-token":token
      }
    }else{
      console.log('请求头位置，正式开发这里设置请求头参数');
    }
    nprogress.start()
    return config
  },error=>{
    return Promise.reject(error)
})

// 拦截器，响应拦截
instance.interceptors.response.use(res=>{
  nprogress.done()
  return res
},error=>{
  nprogress.done()
  return Promise.reject(error)
})


//! 抛出实例
export default instance;